<?php

namespace Admin\Model;

use Common\Model\QuestionModel as CommonQuestionModel;

class QuestionModel extends CommonQuestionModel
{
    /**
     * 问题列表填充字段
     *
     * @param array $item
     * @return array
     */
    public function fill($item)
    {
        $item['url'] = $this->view_url($item['id']);
        $item['addtime_str'] = daterange($item['addtime']);
        $item['audit_str'] = $this->get_audit($item['audit']);
        $item['user'] = D('User')->get_user_one($item['uid'], true, 1);
        $item['tag'] = D('QuestionTag')->get_tag_qid($item['id']);
        $item['img'] = D('QuestionImg')->get_img_qid($item['id']);
        $item['cat'] = D('Category')->find($item['category1']);
        $item['title'] = trim($item['title']) ? $item['title'] : $item['describe'];

        return $item;
    }

    public function question_audit($status, $ids)
    {
        $map['id'] = array('IN', $ids);
        $data['audit'] = intval($status);

        $qlist = M('Question')->where($map)->select();
        M('Question')->where($map)->save($data);

        $this->on_question_audit($status, $qlist);
    }

    /**
     * 审核问题事件处理
     *
     * @param int   $status 审核后状态
     * @param array $qlist  审核的问题列表
     */
    protected function on_question_audit($status, $qlist)
    {
        $this->update_user_question_sum($qlist);  // 更新用户提问总数
    }


}